/*
 * Created by SharpDevelop.
 * User: David
 * Date: 2006-12-09
 * Time: 08:23
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Collections.Generic;

using tools;
using patterns;

namespace Labb4.Entity
{
	/// <summary>
	/// A key press that can be executed on a control pad
	/// </summary>
	public class KeyCommand : ICommand
	{
		#region members
		
		/// <summary>
		/// The scheduled time of the execution of the key press
		/// </summary>
		private int					m_Time;
		/// <summary>
		/// The key to be pressed/released
		/// </summary>
		private Control.PadKey		m_Key;
		/// <summary>
		/// The action to be executed, true if pressed, false if released
		/// </summary>
		private bool				m_Pressed;
		/// <summary>
		/// A reference to the control pad receiving the key
		/// </summary>
		private ControlPad			m_Receiver;
		
		/// <summary>
		/// The first part of a parameter name
		/// </summary>
		private static string		m_ParamPart1 = "macro_";
		/// <summary>
		/// The second part of a parameter name
		/// </summary>
		private static string		m_ParamPart2A = "_key";
		/// <summary>
		/// The third part of a parameter name
		/// </summary>
		private static string		m_ParamPart2B = "_pressed";
		/// <summary>
		/// The fourth part of a parameter name
		/// </summary>
		private static string		m_ParamPart2C = "_time";
		
		#endregion
		
		#region constructors
		
		/// <summary>
		/// Constructor, intializes members
		/// </summary>
		/// <param name="time">Time of execution of this command</param>
		/// <param name="key">The name of the key to execute</param>
		/// <param name="pressed">What to execute, true to press, false to relase</param>
		/// <param name="receiver">The control pad to execute the command on</param>
		public KeyCommand(int time, string key, bool pressed, ControlPad receiver)
		{
			m_Time = time;
			m_Key = (Control.PadKey)Enum.Parse(typeof(Control.PadKey), key);
			
			m_Pressed = pressed;
			m_Receiver = receiver;
		}
		
		#endregion
		
		#region implemented interface methods
		
		/// <summary>
		/// From interface Command. Executes this command.
		/// </summary>
		public void Execute()
		{
			m_Receiver.Pad(m_Key, m_Pressed);
		}
		
		#endregion
		
		#region properties
		
		/// <summary>
		/// The time of execution of this command (get)
		/// </summary>
		public int Time
		{
			get
			{
				return m_Time;
			}
		}
		
		/// <summary>
		/// The first part of a parameter name (get)
		/// </summary>
		public static string ParamPart1
		{
			get
			{
				return m_ParamPart1;
			}
		}
		
		/// <summary>
		/// The second part of a parameter name (get)
		/// </summary>
		public static string ParamPart2A
		{
			get
			{
				return m_ParamPart2A;
			}
		}
		
		/// <summary>
		/// The third part of a parameter name (get)
		/// </summary>
		public static string ParamPart2B
		{
			get
			{
				return m_ParamPart2B;
			}
		}
		
		/// <summary>
		/// The fourth part of a parameter name (get)
		/// </summary>
		public static string ParamPart2C
		{
			get
			{
				return m_ParamPart2C;
			}
		}
		
		#endregion
	}
}
